// https://vitejs.dev/config/
import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import {NaiveUiResolver} from 'unplugin-vue-components/resolvers'
import {resolve} from 'path'

/**
 * 解析给定路径的绝对路径。
 *
 * @param pathStr 要解析的相对路径字符串。
 * @returns 返回绝对路径的字符串。
 */
const pathResolve = (pathStr: string) => resolve(__dirname, pathStr);

export default defineConfig({
    plugins: [
        vue(),
        Components({
            resolvers: [NaiveUiResolver()],
        })
    ],
    resolve: {
        // 设置路径别名
        // 例如：import Foo from '@/foo'，会自动解析为 'src/foo'
        alias: {
            '@': pathResolve('src'),
            '@assets': pathResolve('src/assets'),
            '@components': pathResolve('src/components'),
            '@utils': pathResolve('src/utils'),
            '@views': pathResolve('src/views'),
            '@router': pathResolve('src/router'),
            '@styles': pathResolve('src/styles'),
            '@store': pathResolve('src/store'),
            '@api': pathResolve('src/api'),
            '@layout': pathResolve('src/layout'),
        }
    },
    // 设置服务器
    server: {
        host: 'localhost',
        port: 8080
    }
})